package com.example.jiangkt.ergongyi.util;

import android.util.Log;

import com.example.jiangkt.ergongyi.R;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by jiangkt on 2018/3/22.
 */

public class CardUtil {
    /**
     * 游戏规则，所有人只跟庄家比大小 因为开牌只有两张牌，根据21点规则，需要分开判断 都是两张牌时，和已经有人摸牌时 以下大小均是根据public class
     * CardUtil { public static int[] cards = new int[]{ R.drawable.spade_a,
     * R.drawable.heart_a, R.drawable.club_a, R.drawable.block_a,
     * R.drawable.spade_2, R.drawable.heart_2, R.drawable.club_2,
     * R.drawable.block_2, R.drawable.spade_3, R.drawable.heart_3,
     * R.drawable.club_3, R.drawable.block_3, R.drawable.spade_4,
     * R.drawable.heart_4, R.drawable.club_4, R.drawable.block_4,
     * R.drawable.spade_5, R.drawable.heart_5, R.drawable.club_5,
     * R.drawable.block_5, R.drawable.spade_6, R.drawable.heart_6,
     * R.drawable.club_6, R.drawable.block_6, R.drawable.spade_7,
     * R.drawable.heart_7, R.drawable.club_7, R.drawable.block_7,
     * R.drawable.spade_8, R.drawable.heart_8, R.drawable.club_8,
     * R.drawable.block_8, R.drawable.spade_9, R.drawable.heart_9,
     * R.drawable.club_9, R.drawable.block_9, R.drawable.spade_10,
     * R.drawable.heart_10, R.drawable.club_10, R.drawable.block_10,
     * R.drawable.spade_j, R.drawable.heart_j, R.drawable.club_j,
     * R.drawable.block_j, R.drawable.spade_q, R.drawable.heart_q,
     * R.drawable.club_q, R.drawable.block_q, R.drawable.spade_k,
     * R.drawable.heart_k, R.drawable.club_k, R.drawable.block_k,
     * R.drawable.joker_heart,
     * R.drawable.joker_spade,R.drawable.card_back,R.color.colorTransparent}; } 进行判断
     */
    //两种情况,两种情况的区别只有 J Q K的值不一样
    //--判断开牌时所有玩家只有两张牌时的情况
    public static final Map<String, Integer> DEALCARDMAP = new HashMap<>();
    //--判断已经抓牌以后的情况
    public static final Map<String, Integer> SIZECARDMAP = new HashMap<>();
    static {
        DEALCARDMAP.put("0", 1);
        DEALCARDMAP.put("1", 1);
        DEALCARDMAP.put("2", 1);
        DEALCARDMAP.put("3", 1);
        DEALCARDMAP.put("4", 2);
        DEALCARDMAP.put("5", 2);
        DEALCARDMAP.put("6", 2);
        DEALCARDMAP.put("7", 2);
        DEALCARDMAP.put("8", 3);
        DEALCARDMAP.put("9", 3);
        DEALCARDMAP.put("10",3);
        DEALCARDMAP.put("11", 3);
        DEALCARDMAP.put("12", 4);
        DEALCARDMAP.put("13", 4);
        DEALCARDMAP.put("14", 4);
        DEALCARDMAP.put("15", 4);
        DEALCARDMAP.put("16", 5);
        DEALCARDMAP.put("17", 5);
        DEALCARDMAP.put("18", 5);
        DEALCARDMAP.put("19", 5);
        DEALCARDMAP.put("20", 6);
        DEALCARDMAP.put("21", 6);
        DEALCARDMAP.put("22", 6);
        DEALCARDMAP.put("23", 6);
        DEALCARDMAP.put("24", 7);
        DEALCARDMAP.put("25", 7);
        DEALCARDMAP.put("26", 7);
        DEALCARDMAP.put("27", 7);
        DEALCARDMAP.put("28", 8);
        DEALCARDMAP.put("29", 8);
        DEALCARDMAP.put("30", 8);
        DEALCARDMAP.put("31", 8);
        DEALCARDMAP.put("32",9);
        DEALCARDMAP.put("33", 9);
        DEALCARDMAP.put("34", 9);
        DEALCARDMAP.put("35", 9);
        DEALCARDMAP.put("36", 10);
        DEALCARDMAP.put("37", 10);
        DEALCARDMAP.put("38", 10);
        DEALCARDMAP.put("39", 10);
        DEALCARDMAP.put("40", 11);
        DEALCARDMAP.put("41", 11);
        DEALCARDMAP.put("42", 11);
        DEALCARDMAP.put("43", 11);
        DEALCARDMAP.put("44", 12);
        DEALCARDMAP.put("45", 12);
        DEALCARDMAP.put("46", 12);
        DEALCARDMAP.put("47", 12);
        DEALCARDMAP.put("48", 13);
        DEALCARDMAP.put("49", 13);
        DEALCARDMAP.put("50", 13);
        DEALCARDMAP.put("51", 13);

        SIZECARDMAP.put("0", 1);
        SIZECARDMAP.put("1", 1);
        SIZECARDMAP.put("2", 1);
        SIZECARDMAP.put("3", 1);
        SIZECARDMAP.put("4", 2);
        SIZECARDMAP.put("5", 2);
        SIZECARDMAP.put("6", 2);
        SIZECARDMAP.put("7", 2);
        SIZECARDMAP.put("8", 3);
        SIZECARDMAP.put("9", 3);
        SIZECARDMAP.put("10",3);
        SIZECARDMAP.put("11",3);
        SIZECARDMAP.put("12", 4);
        SIZECARDMAP.put("13", 4);
        SIZECARDMAP.put("14", 4);
        SIZECARDMAP.put("15", 4);
        SIZECARDMAP.put("16", 5);
        SIZECARDMAP.put("17", 5);
        SIZECARDMAP.put("18", 5);
        SIZECARDMAP.put("19", 5);
        SIZECARDMAP.put("20", 6);
        SIZECARDMAP.put("21", 6);
        SIZECARDMAP.put("22", 6);
        SIZECARDMAP.put("23", 6);
        SIZECARDMAP.put("24", 7);
        SIZECARDMAP.put("25", 7);
        SIZECARDMAP.put("26", 7);
        SIZECARDMAP.put("27", 7);
        SIZECARDMAP.put("28", 8);
        SIZECARDMAP.put("29", 8);
        SIZECARDMAP.put("30", 8);
        SIZECARDMAP.put("31", 8);
        SIZECARDMAP.put("32", 9);
        SIZECARDMAP.put("33", 9);
        SIZECARDMAP.put("34", 9);
        SIZECARDMAP.put("35", 9);
        SIZECARDMAP.put("36", 10);
        SIZECARDMAP.put("37", 10);
        SIZECARDMAP.put("38", 10);
        SIZECARDMAP.put("39", 10);
        SIZECARDMAP.put("40", 10);
        SIZECARDMAP.put("41", 10);
        SIZECARDMAP.put("42", 10);
        SIZECARDMAP.put("43", 10);
        SIZECARDMAP.put("44", 10);
        SIZECARDMAP.put("45", 10);
        SIZECARDMAP.put("46", 10);
        SIZECARDMAP.put("47", 10);
        SIZECARDMAP.put("48", 10);
        SIZECARDMAP.put("49", 10);
        SIZECARDMAP.put("50", 10);
        SIZECARDMAP.put("51", 10);
    }
    
    
    public  static  int[] cards = new int[]{
            R.drawable.spade_a, R.drawable.heart_a, R.drawable.club_a, R.drawable.block_a,
            R.drawable.spade_2, R.drawable.heart_2, R.drawable.club_2, R.drawable.block_2,
            R.drawable.spade_3, R.drawable.heart_3, R.drawable.club_3, R.drawable.block_3,
            R.drawable.spade_4, R.drawable.heart_4, R.drawable.club_4, R.drawable.block_4,
            R.drawable.spade_5, R.drawable.heart_5, R.drawable.club_5, R.drawable.block_5,
            R.drawable.spade_6, R.drawable.heart_6, R.drawable.club_6, R.drawable.block_6,
            R.drawable.spade_7, R.drawable.heart_7, R.drawable.club_7, R.drawable.block_7,
            R.drawable.spade_8, R.drawable.heart_8, R.drawable.club_8, R.drawable.block_8,
            R.drawable.spade_9, R.drawable.heart_9, R.drawable.club_9, R.drawable.block_9,
            R.drawable.spade_10, R.drawable.heart_10, R.drawable.club_10, R.drawable.block_10,
            R.drawable.spade_j, R.drawable.heart_j, R.drawable.club_j, R.drawable.block_j,
            R.drawable.spade_q, R.drawable.heart_q, R.drawable.club_q, R.drawable.block_q,
            R.drawable.spade_k, R.drawable.heart_k, R.drawable.club_k, R.drawable.block_k,
            R.drawable.joker_heart, R.drawable.joker_spade,R.drawable.card_back,R.color.colorTransparent};

    /**
     * 抓牌以后两张牌的情况时牌的大小 封装手中所有牌的joker大小，大于21点就爆, A的大小转换成11点
     *
     * @param selfCards
     * @return
     */
    public static int getSecondSizeCardValue(List<Integer> selfCards) {
        int cardValue = 0;
        for (int i = 0; i < selfCards.size(); i++) {
            cardValue += SIZECARDMAP.get(selfCards.get(i).toString()) == 1
                    ? SIZECARDMAP.get(selfCards.get(i).toString())+10
                    : SIZECARDMAP.get(selfCards.get(i).toString());
        }
        //如果A大于1张牌，则其他A的值都返回1，因为两张A都变成11点就大于21点了
        cardValue+=getACardCount(selfCards)>1?(-(getACardCount(selfCards)-1)*10):0;
        Log.e("getSecondSizeCardValue",cardValue+"");
        return cardValue;
    }
    public static int getFirstSizeCardValue(List<Integer> selfCards) {
        int cardValue = 0;
        for (int i = 0; i < selfCards.size(); i++) {
            cardValue += SIZECARDMAP.get(selfCards.get(i).toString());
        }
        Log.e("getFirstSizeCardValue",cardValue+"");
        return cardValue;
    }

    /**
     * 开局时每个玩家只有两张牌时的大小,A 的大小是1
     *
     * @param selfCards
     * @return
     */
    public static int getDealCardValue(List<Integer> selfCards) {
        int cardValue = 0;
        for (int i = 0; i < selfCards.size(); i++) {
            cardValue += DEALCARDMAP.get(selfCards.get(i).toString());
        }

        Log.e("getDealCardValue",cardValue+"");
        return cardValue;
    }

    /**
     * 获得玩家手中A的数量
     *
     * @param selfCards
     * @return
     */
    public static int getACardCount(List<Integer> selfCards) {
        int count = 0;
        for (int i = 0; i < selfCards.size(); i++) {
            if (DEALCARDMAP.get(selfCards.get(i).toString()) == 1) {
                count++;
            }
        }
        Log.e("getACardCount",count+"");
        return count;
    }

}
